//------交通事故快速处理------
var accidentCaseType=[
 {"checked":false, "AccidentCaseTypeId":1, "Name":"追尾"},
 {"checked":false, "AccidentCaseTypeId":2, "Name":"逆行"},
 {"checked":false, "AccidentCaseTypeId":3, "Name":"倒车"},
 {"checked":false, "AccidentCaseTypeId":4, "Name":"溜车"},
 {"checked":false, "AccidentCaseTypeId":5, "Name":"开关车门"},
 {"checked":false, "AccidentCaseTypeId":6, "Name":"违反交通信号"},
 {"checked":false, "AccidentCaseTypeId":7, "Name":"未按规定让行"},
 {"checked":false, "AccidentCaseTypeId":8, "Name":"其它情形"}
 ];

 var aDuty=[
    {"checked":false, "checkId":1, "Name":"全部责任"},
    {"checked":false, "checkId":2, "Name":"无责任"}
];

var bDuty=[
    {"checked":false, "checkId":1, "Name":"全部责任"},
    {"checked":false, "checkId":2, "Name":"无责任"}
];
/*
 gblFooterType:footer类型
 sns:微社区底部
 accidentDetail:交通事故快速处理详情footer
 award:文明交通footer
 award_question:文明交通答题footer
*/
var gblFooterType = { "sns": "sns", accidentDetail: "accident_detail", award: "award", awardQuestion: "award_question", treasuryQuestion: "treasury_question" };
//--------------------------------------
//初始化rootScope变量
function initRootScope(rootScope)
{
    rootScope.canRemoveAction = false;//默认不需要清空消息
    rootScope.hasFooter = false;//默认不需要footer
    rootScope.canCreateTopic = false;//默认不需要发表话题
    rootScope.canCreateReply = false;//默认不需要回复
    rootScope.hasMyForum = false;//默认不需要我的微社区
    rootScope.isPending = false;//默认不需要pending
    rootScope.notHaveHeader=false;//默认需要头部
    rootScope.gblFooterType=gblFooterType.sns;//底部类型，默认微社区
}
function getParameterFromUrl(name)
{
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

    var url = window.location.href;

    var paramString;
    if(url.indexOf("#")){
        if(url.indexOf("#")>=url.indexOf("?")){
            paramString = url.slice(url.indexOf("?")+1,url.indexOf("#"));
        }else{
            paramString = url.slice(url.indexOf("?")+1,url.length);
        }
    }else{
        paramString = window.location.search.substring(1);
    }
    var r = paramString.match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

function getStorageValue(key)
{
    var data = getParameterFromUrl(key);
    if(data==''||data==null)
        data=localStorage.getItem(key);
    else
        localStorage.setItem(key,data);
    return data;
}

function is_touch_device() {
  return !!('ontouchstart' in window);
}

var isLocalDebug = false;
var domain = getStorageValue("snsEnv");
if(isLocalDebug)
 domain = "qa.yunchelife.com";
var useDummy = false;
var useLog = false;

/*
 有两个值list和single,list表明话题以list形式显示 如在所有话题，single单独显示，如在话题明细中
**/
var mctopicDirectiveMode= {list:1,single:2};

/*
   支付场景
  1: 报名学车 LDE :Learn driving enrollment
*/
var payScene={LDE:1};

/*
支付方式
1：线下支付
2：在线全付
3：在线预付
* */
var payMethod={undefined:0,payOffline:1,payAllOnline:2,prepaidOnline:3};

var app = angular.module('app', ['ngRoute', 'ngAnimate', 'ngCookies', 'localization', 'ui.bootstrap','LocalStorageModule']).config(
	["$routeProvider", function($routeProvider){
		$routeProvider.
            when('/about', {templateUrl: 'views/about/index.html', controller: 'AboutIndexController'}).
            when('/about/content', {templateUrl: 'views/about/content.html', controller: 'AboutContentController'}).
            when('/about/privacy', {templateUrl: 'views/about/privacy.html', controller: 'AboutPrivacyController'}).
			when('/enroll', {templateUrl: 'views/enroll.html', controller: 'EnrollController'}).
			when('/enrollStatus', {templateUrl: 'views/enroll_status.html', controller: 'EnrollStatusController'}).
            when('/region', {templateUrl: 'views/region.html', controller: 'RegionController'}).
			when('/drivingSchool', {templateUrl: 'views/driving_school.html', controller: 'DrivingSchoolController'}).

            //when('/', {templateUrl: 'views/accident/accident_nav.html', controller: 'accidentNavController'}).
 			when('/', {templateUrl: 'views/clubs.html', controller: 'ClubsController'}).
            when('/rank', {templateUrl: 'views/rank.html', controller: 'RankController'}).
			when('/club/:snsClubId', {templateUrl: 'views/club.html', controller: 'ClubController'}).	
            when('/myclub/:snsClubId', {templateUrl: 'views/club.html', controller: 'ClubController'}).   
            when('/userclub/:snsClubId', {templateUrl: 'views/club.html', controller: 'ClubController'}). 
            when('/myforum', {templateUrl: 'views/myforum.html', controller: 'MyForumController'}).   
            when('/userforum', {templateUrl: 'views/userforum.html', controller: 'UserForumController'}). 
            when('/userforum/:snsClubId', {templateUrl: 'views/userforum.html', controller: 'UserForumController'}). 

            when('/myclub', {templateUrl: 'views/myclub.html', controller: 'MyClubController'}).    
            when('/userclub', {templateUrl: 'views/userclub.html', controller: 'UserClubController'}).   
            when('/mytopic', {templateUrl: 'views/mytopic.html', controller: 'MyTopicController'}).  
            when('/usertopic', {templateUrl: 'views/mytopic.html', controller: 'UserTopicController'}).  
            when('/topic/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).  
            when('/myclub/:snsClubId/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).
            when('/userclub/:snsClubId/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).
            when('/club/:snsClubId/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).  
            when('/mytopic/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).   
            when('/usertopic/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).   
            when('/myaction', {templateUrl: 'views/myaction.html', controller: 'MyActionController'}).   
            when('/myaction/:snsTopicId', {templateUrl: 'views/topic_detail.html', controller: 'TopicDetailController'}).  
			when('/question/:questionId', {templateUrl: 'views/question.html', controller: 'QuestionController'}).	
			when('/createClub', {templateUrl: 'views/create_club.html', controller: 'CreateClubController'}).	
			when('/createTopic/:snsClubId', {templateUrl: 'views/create_topic.html', controller: 'CreateTopicController'}).
            when('/employeeVote', {templateUrl: 'views/employeeVote.html', controller: 'EmployeeVoteController'}).
            when('/voterValidation', {templateUrl: 'views/voterValidation.html', controller: 'VoterValidationController'}).
            when('/choosePayType/:payScene', {templateUrl: 'views/choosePayType.html', controller: 'ChoosePayTypeController'}).
            when('/accident', {templateUrl: 'views/accident/menu.html', controller: 'accidentMenuController'}).
            when('/accident/nav', {templateUrl: 'views/accident/accident_nav.html', controller: 'accidentNavController'}).
            when('/accident/agreement/menu', {templateUrl: 'views/accident/agreement_menu.html', controller: 'accidentAgreementMenuController'}).
            when('/accident/agreement', {templateUrl: 'views/accident/agreement.html', controller: 'accidentAgreementController'}).
            when('/accident/caseMenu', {templateUrl: 'views/accident/case_menu.html', controller: 'accidentCaseMenuController'}).
            when('/accident/agreement/get', {templateUrl: 'views/accident/agreement_get.html', controller: 'accidentAgreementGetController'}).
            when('/accident/case/:index', {templateUrl: 'views/accident/case_detail.html', controller: 'accidentCaseDetailController'}).
            when('/accident/dissent', { templateUrl: 'views/accident/dissent.html', controller: 'accidentDissentController' }).
            when('/accident/carInfo/enroll', { templateUrl: 'views/accident/car_info_enroll.html', controller: 'accidentCarInfoEnrollController' }).
            when('/accident/carInfo/promptEnroll', { templateUrl: 'views/accident/car_info_prompt_enroll.html', controller: 'accidentCarInfoPromptEnrollController' }).
            // award start
            when('/award', { templateUrl: 'views/award/index.html', controller: 'AwardController' }).
            when('/award/done', { templateUrl: 'views/award/done.html', controller: 'AwardDoneController' }).
            when('/award/ranking', { templateUrl: 'views/award/ranking.html', controller: 'AwardRankingController' }).
            when('/award/question/:questionId', { templateUrl: 'views/award/question.html', controller: 'AwardQuestionController' }).
            when('/award/myscore', { templateUrl: 'views/award/myscore.html', controller: 'AwardMyScoreController' }).
            // award end

            // treasury start
            when('/treasury/', { templateUrl: 'views/treasury/home.html', controller: 'TreasuryHomeController' }).
			when('/treasury/exam', { templateUrl: 'views/treasury/exam.html', controller: 'TreasuryExamController' }).
			when('/treasury/question/:questionId', { templateUrl: 'views/treasury/question.html', controller: 'TreasuryQuestionController' }).
            when('/treasury/submenu/:subjectId', { templateUrl: 'views/treasury/submenu.html', controller: 'TreasurySubmenuController' }).
            when('/treasury/subitem/:subjectId', { templateUrl: 'views/treasury/subitem.html', controller: 'TreasurySubitemController' }).
            when('/treasury/question/:questionId/type/:type', { templateUrl: 'views/treasury/question.html', controller: 'TreasuryQuestionController' }).
            // type[1: my errors; 2: mock exam; 3: mock examl my errors first, 4: section exam, 5: random exam ]
			when('/treasury/question/:questionId/type/:type/section/:sectionId', { templateUrl: 'views/treasury/question.html', controller: 'TreasuryQuestionController' }).
            when('/treasury/result/:resultId', { templateUrl: 'views/treasury/result.html', controller: 'TreasuryResultController' }).
            when('/treasury/video', { templateUrl: 'views/treasury/video.html', controller: 'TreasuryVideoController' }).
            when('/treasury/section', { templateUrl: 'views/treasury/section.html', controller: 'TreasurySectionController' }).
            when('/treasury/error', { templateUrl: 'views/treasury/error.html', controller: 'TreasuryErrorController' }).
            // treasury end

           /* when('/accident/carInfo', {templateUrl: 'views/car_info.html', controller: 'carInfoController'}).*/
			// for sign up
			
			
			otherwise({redirectTo: '/'});
	}]
).config(function($sceProvider){
	$sceProvider.enabled(false);
}).config(function (localStorageServiceProvider) {
    localStorageServiceProvider
      .setPrefix('CCLife')
});

// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

var browser={ 
    versions:function(){ 
        var u = navigator.userAgent, app = navigator.appVersion; 
        return { 
            trident: u.indexOf('Trident') > -1, //IE
            presto: u.indexOf('Presto') > -1, //opera
            webKit: u.indexOf('AppleWebKit') > -1, //webkit
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //firefox
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //mobile
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android or uc
            iPhone: u.indexOf('iPhone') > -1 , //iPhone QQHD 
            iPad: u.indexOf('iPad') > -1, //iPad 
            webApp: u.indexOf('Safari') == -1
        }; 
    }(), 
    language:(navigator.browserLanguage || navigator.language).toLowerCase() 
} 
function iOS7() {
	if (/iP(hone|od|ad)/.test(navigator.platform)) {
		var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
		var vers = [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
		if(vers[0] >=7)
			return true;
		return false;
	}
	return false;
}

//for ios
var connectWebViewJavascriptBridge = function(callback){
    if (window.WebViewJavascriptBridge) {
        callback(WebViewJavascriptBridge)
    } else {
        document.addEventListener('WebViewJavascriptBridgeReady', function() {
            callback(WebViewJavascriptBridge)
        }, false)
    }
};
if(browser.versions.ios){
	connectWebViewJavascriptBridge(function(bridge){
		bridge.init(function(message, responseCallback) {
			var data = { 'Javascript Responds':'Wee!' };
			console.log('JS responding with', data)
			responseCallback(data)
		});
		bridge.registerHandler("uploadImageCallback", function(data, responseCallback) {
			console.log("uploadImageCallback", data)
			
			var evt = document.createEvent("Events");
			evt.data = data;
			evt.initEvent("FILE_UPLOADED_EVENT", false, true);

			document.dispatchEvent(evt);
			
			var responseData = { 'Javascript Says':'got images!' }
			responseCallback(responseData)
		});
		bridge.registerHandler("uploadImageCancelCallback", function(data, responseCallback) {
			console.log("uploadImageCancelCallback", data)

			var evt = document.createEvent("Events");
			evt.data = data;
			evt.initEvent("FILE_UPLOAD_CANCEL_EVENT", false, true);

			document.dispatchEvent(evt);

			var responseData = { 'Javascript Says':'cancel upload!' }
			responseCallback(responseData)
		});
		
	});
}

// for android
if(browser.versions.android && jsb && jsb.addJavascriptMethod){

    //Log.log("android: " , browser.versions)
    jsb.addJavascriptMethod('uploadImageCallback', function(params){
        Log.log("called by native: uploadImageCallback=====")
        var evt = document.createEvent("Events");
        evt.data = params;
        evt.initEvent("FILE_UPLOADED_EVENT", false, true);

        document.dispatchEvent(evt);
        Log.log("FILE_UPLOADED_EVENT dispatched")
        return {'text': 'uploadImageCallback ok'};
    });

    jsb.addJavascriptMethod('uploadImageCancelCallback', function(params){
        Log.log("called by native: uploadImageCancelCallback=====")
        var evt = document.createEvent("Events");
        evt.data = params;
        evt.initEvent("FILE_UPLOAD_CANCEL_EVENT", false, true);

        document.dispatchEvent(evt);
        
        return {'text': 'uploadImageCancelCallback ok'};
    });

    jsb.addJavascriptMethod('backCallback', function(params){
        Log.log("called by native: backCallback=====")
        var evt = document.createEvent("Events");
        evt.data = params;
        evt.initEvent("NAVIGATION_BACK_EVENT", false, true);

        document.dispatchEvent(evt);
        
        return {'text': 'backCallback ok'};
    });
}
function getIdCardInfo(cardNo) {
	if(!cardNo)
		return false;
    var info = {
        isTrue : false,
        year : null,
        month : null,
        day : null,
        isMale : false,
        isFemale : false
    };
    if (!cardNo && 15 != cardNo.length && 18 != cardNo.length) {
        info.isTrue = false;
        return info;
    }
    if (15 == cardNo.length) {
        var year = cardNo.substring(6, 8);
        var month = cardNo.substring(8, 10);
        var day = cardNo.substring(10, 12);
        var p = cardNo.substring(14, 15); //
        var birthday = new Date(year, parseFloat(month) - 1,
                parseFloat(day));
        if (birthday.getYear() != parseFloat(year)
                || birthday.getMonth() != parseFloat(month) - 1
                || birthday.getDate() != parseFloat(day)) {
            info.isTrue = false;
        } else {
            info.isTrue = true;
            info.year = birthday.getFullYear();
            info.month = birthday.getMonth() + 1;
            info.day = birthday.getDate();
            if (p % 2 == 0) {
                info.isFemale = true;
                info.isMale = false;
            } else {
                info.isFemale = false;
                info.isMale = true
            }
        }
        return info;
    }
    if (18 == cardNo.length) {
        var year = cardNo.substring(6, 10);
        var month = cardNo.substring(10, 12);
        var day = cardNo.substring(12, 14);
        var p = cardNo.substring(14, 17)
        var birthday = new Date(year, parseFloat(month) - 1,
                parseFloat(day));
        if (birthday.getFullYear() != parseFloat(year)
                || birthday.getMonth() != parseFloat(month) - 1
                || birthday.getDate() != parseFloat(day)) {
            info.isTrue = false;
            return info;
        }
        var Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ]; 
        var Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ];
        var sum = 0; 
        var _cardNo = cardNo.split("");
        if (_cardNo[17].toLowerCase() == 'x') {
            _cardNo[17] = 10;
        }
        for ( var i = 0; i < 17; i++) {
            sum += Wi[i] * _cardNo[i]; 
        }
        var i = sum % 11;
        if (_cardNo[17] != Y[i]) {
            return info.isTrue = false;
        }

        info.isTrue = true;
        info.year = birthday.getFullYear();
        info.month = birthday.getMonth() + 1;
        info.day = birthday.getDate();
        if (p % 2 == 0) {
            info.isFemale = true;
            info.isMale = false;
        } else {
            info.isFemale = false;
            info.isMale = true
        }
        return info;
    }
    return info;
}
/*
remove the emoji relevant code for now

var emot={    
};

var defCss = "";
var def = {};
function createEmojiStyles(){

    var inc=0;
    for(itm in emot){
        //smile:{title:"Smile",codes:["[微笑]",":)",":=)",":-)"]},
    //.emoticon-smile { background-position: 0 0; }
        def[itm] = {title: emot[itm].title, codes: emot[itm].codes};
        defCss += ".emoticon-" + itm + " { background-position: " + (-1 - inc%14*31) + "px " + (-4 - Math.floor(inc/14)*31) + "px; }" ;
        inc++;
    }
    console.log(defCss);
}
createEmojiStyles();
*/
